/*
 * *****************************************************************************
 * Copyright (C) 2014-2024 Dennis Sheirer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 * ****************************************************************************
 */

// Generated by jextract

package io.github.dsheirer.source.tuner.sdrplay.api.v3_07;

import java.lang.foreign.Arena;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentAllocator;
import java.util.function.Consumer;

import static java.lang.foreign.MemoryLayout.PathElement.groupElement;
import static java.lang.foreign.ValueLayout.OfDouble;
import static java.lang.foreign.ValueLayout.OfInt;

/**
 * {@snippet lang=c :
 * struct {
 *     unsigned int gRdB;
 *     unsigned int lnaGRdB;
 *     double currGain;
 * }
 * }
 */
public class sdrplay_api_GainCbParamT {

    sdrplay_api_GainCbParamT() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        sdrplay_api_h.C_INT.withName("gRdB"),
        sdrplay_api_h.C_INT.withName("lnaGRdB"),
        sdrplay_api_h.C_DOUBLE.withName("currGain")
    ).withName("$anon$31:9");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final OfInt gRdB$LAYOUT = (OfInt)$LAYOUT.select(groupElement("gRdB"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned int gRdB
     * }
     */
    public static final OfInt gRdB$layout() {
        return gRdB$LAYOUT;
    }

    private static final long gRdB$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned int gRdB
     * }
     */
    public static final long gRdB$offset() {
        return gRdB$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned int gRdB
     * }
     */
    public static int gRdB(MemorySegment struct) {
        return struct.get(gRdB$LAYOUT, gRdB$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned int gRdB
     * }
     */
    public static void gRdB(MemorySegment struct, int fieldValue) {
        struct.set(gRdB$LAYOUT, gRdB$OFFSET, fieldValue);
    }

    private static final OfInt lnaGRdB$LAYOUT = (OfInt)$LAYOUT.select(groupElement("lnaGRdB"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * unsigned int lnaGRdB
     * }
     */
    public static final OfInt lnaGRdB$layout() {
        return lnaGRdB$LAYOUT;
    }

    private static final long lnaGRdB$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * unsigned int lnaGRdB
     * }
     */
    public static final long lnaGRdB$offset() {
        return lnaGRdB$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * unsigned int lnaGRdB
     * }
     */
    public static int lnaGRdB(MemorySegment struct) {
        return struct.get(lnaGRdB$LAYOUT, lnaGRdB$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * unsigned int lnaGRdB
     * }
     */
    public static void lnaGRdB(MemorySegment struct, int fieldValue) {
        struct.set(lnaGRdB$LAYOUT, lnaGRdB$OFFSET, fieldValue);
    }

    private static final OfDouble currGain$LAYOUT = (OfDouble)$LAYOUT.select(groupElement("currGain"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * double currGain
     * }
     */
    public static final OfDouble currGain$layout() {
        return currGain$LAYOUT;
    }

    private static final long currGain$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * double currGain
     * }
     */
    public static final long currGain$offset() {
        return currGain$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * double currGain
     * }
     */
    public static double currGain(MemorySegment struct) {
        return struct.get(currGain$LAYOUT, currGain$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * double currGain
     * }
     */
    public static void currGain(MemorySegment struct, double fieldValue) {
        struct.set(currGain$LAYOUT, currGain$OFFSET, fieldValue);
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}

